#pragma once

#include "Command.h"

#include <memory>
#include <vector>
#include <string>

class Component
{
public:
	Component(const std::string &name);
	virtual ~Component();

	const std::string &getName() const { return name; }

	void add(const CommandPtr &command);
	template<class CommandType> std::shared_ptr<CommandType> add(const CommandPtr &command);
	void remove(const CommandPtr &command);
	const std::vector<CommandPtr> &getCommands() const { return commands; }
	bool hasCommand(const CommandPtr &command);

	virtual void update(unsigned int /*tick*/) {}

protected:
	std::string name;
	std::vector<CommandPtr> commands;
};
typedef std::shared_ptr<Component> ComponentPtr;

template<class CommandType> 
inline std::shared_ptr<CommandType> Component::add(const CommandPtr &command)
{
	commands.push_back(command);
	return std::dynamic_pointer_cast<CommandType>(command);
}
